package com.soonfor.evaluate.tools;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.estronger.shopmanage.utils.ActivityUtils;
import com.soonfor.evaluate.tools.dialog.normal.NormalDialog;
import com.soonfor.evaluate.tools.dialog.normal.OnBtnClickL;

public class CustomDialog {
    static CustomDialog custDialog;

    private CustomDialog() {
    }

    public static CustomDialog getInstance() {
        if (custDialog == null) {
            synchronized (CustomDialog.class) {
                if (custDialog == null) {
                    custDialog = new CustomDialog();
                }
            }
        }
        return custDialog;
    }
    /**
     * 对话框start
     **/
    public static NormalDialog getNormalDialog(Context mContext, String title, String msg, OnBtnClickL blistener) {
        if (mContext != null && ActivityUtils.isRunning((Activity) mContext)) {
            final NormalDialog dialog = new NormalDialog(mContext);
            dialog.content(msg)
                    .style(NormalDialog.STYLE_ONE)//
                    .title(title)
                    .titleTextSize(18)//
                    .show();
            dialog.setOnBtnClickL(
                    new OnBtnClickL() {
                        @Override
                        public void onBtnClick(View view) {
                            dialog.dismiss();
                        }
                    },
                    blistener);
            return dialog;
        } else {
            return null;
        }
    }

    /**
     * 对话框start
     * 上面得点确定dialog隐藏不了，增加了下面的
     **/
    public static NormalDialog getCanDismissDialog(Context mContext, String title, String msg, final OnBtnClickL blistener) {
        if (mContext != null && ActivityUtils.isRunning((Activity) mContext)) {
            final NormalDialog dialog = new NormalDialog(mContext);
            dialog.content(msg)
                    .style(NormalDialog.STYLE_ONE)//
                    .title(title)
                    .titleTextSize(18)//
                    .show();
            dialog.setOnBtnClickL(
                    new OnBtnClickL() {
                        @Override
                        public void onBtnClick(View view) {
                            dialog.dismiss();
                        }
                    },
                    new OnBtnClickL() {
                        @Override
                        public void onBtnClick(View view) {
                            if (blistener != null){
                                blistener.onBtnClick(view);
                            }
                            dialog.dismiss();
                        }
                    });
            return dialog;
        } else {
            return null;
        }
    }
}
